/*
 * @Descripttion: 文件说明
 * @version: 0.0.1
 * @Author: gaojiapeng
 * @Date: 2020-06-23 10:39:22
 * @LastEditors: gaojiapeng
 * @LastEditTime: 2021-03-14 14:42:32
 */
import axios from "axios";
import { Message } from "element-ui";
import de from "element-ui/src/locale/lang/de";
// 创建axios实例
const service = axios.create({
  timeout: 20000 // ms请求超时时间
});

// request拦截器
service.interceptors.request.use(
  config => {
    if (localStorage.getItem('accessToken')) {
      config.headers.common['Authorization'] = localStorage.getItem('accessToken')
    }else {
      config.headers.common['Authorization'] = 'basic TkRjNE1Ua3pOMlkyWkROa09XRmk6T1daa05tTm1OR0poT1RFeE5qazI='
    }
    return config;
  },
  error => {
    // Do something with request error
    Promise.reject(error);
  }
);

// respone拦截器
service.interceptors.response.use(
  response => {
    return response;
    /*const Data = response;*/
/*    if (Data.status !== 200) {
      return Promise.reject();
    } else {
      const newRes = Data.data;
      if (newRes.code !== 200) {
        Message({
          showClose: true,
          message: newRes.info,
          type: "error"
        });
        return Promise.reject();
      }
      return Data.data.data;
    }*/
  },
  error => {
    console.log(error.message);
    return Promise.reject(error);
  }
);

export default service;
